﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Meeting.Public;

namespace Meeting.Web.Admin.MeetingAfter
{
    /// <summary>
    /// VoteStatisticsOperation 的摘要说明
    /// </summary>
    public class VoteStatisticsOperation : IHttpHandler
    {

        string methodName = "";
        int nPageIndex = 1;
        int nPageSize = 4;

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json;charset=utf-8";

            nPageIndex = CommonFunction.varToIntDef(context.Request.Params["page"], 1);
            nPageSize = CommonFunction.varToIntDef(context.Request.Params["rows"], 15);
            methodName = context.Request.Params["method"];
            switch (methodName)
            {
                case "GetMeetingVote":
                    GetMeetingVote(context);
                    break;
                case "GetVoteResult":
                    GetVoteResult(context);
                    break;
            }
        }
        BLL.MeetingExt bll = new BLL.MeetingExt();
        //获取文件
        private void GetMeetingVote(HttpContext context)
        {
            //throw new NotImplementedException();
            string Name = context.Request.Params["Name"];
            string Begin = context.Request.Params["Begin"];
            string End = context.Request.Params["End"];

            string sF = " 1=1 ";
            if (!string.IsNullOrEmpty(Name)) sF += " And  Vote.Theme  Like '%" + Name + "%' ";

            if (!string.IsNullOrEmpty(Begin)) sF += " And Vote.StartDate >= '" + Begin + "' ";
            if (!string.IsNullOrEmpty(End)) sF += " And  Vote.StartDate <= '" + End + "' ";

            context.Response.Write(bll.GetMeetingVote(nPageIndex, nPageSize, sF));
        }

        private void GetVoteResult(HttpContext context)
        {
            int meetingId = CommonFunction.varToIntDef(context.Request["MeetingId"], 0); ;
            int voteId = CommonFunction.varToIntDef(context.Request["Id"], 0);
            string Category = CommonFunction.VarToStr(context.Request["Category"]);
            BLL.Vote bllVote = new BLL.Vote();
            if (Category != "4")
            {
                context.Response.Write(bllVote.GetVoteResult(meetingId, voteId));
            }
            else
            {
                context.Response.Write(bllVote.GetVoteResult_Office(meetingId, voteId));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}